import { AttrType } from "./attr/AttrType";
import { BattleRole } from "./role/BattleRole";

/**
 * 战斗计算类
 */
export class BattleFormula {
    /**命中率 */
    static getHitRate(caster: BattleRole, target: BattleRole): number {
        let n1 = caster.attrMgr.getAttr(AttrType.hitRate);
        let n2 = target.attrMgr.getAttr(AttrType.dodgeRate);

        return 1 - Math.max(n2 - n1, 0);
    }

    /**基础伤害 */
    static getBaseDamage(caster: BattleRole, target: BattleRole, power: number) {
        let atk = this.getAtk(caster);
        let defense = this.getDefense(target);

        let damage = Math.max(atk - defense, 0) * power;

        return damage >> 0;
    }

    /**(攻击力、攻击力加成在这里算) */
    static getAtk(caster: BattleRole): number {
        // let rate = caster.attrMgr.getAttr(AttrType.atk)
        let atk = caster.attrMgr.getAttr(AttrType.atk);
        return atk;
    }

    /**(防御力、防御力加成在这里算) */
    static getDefense(caster: BattleRole): number {
        // let rate = caster.attrMgr.getAttr(AttrType.atk)
        let defense = caster.attrMgr.getAttr(AttrType.defense);
        return defense;
    }

    /**暴击几率 */
    static getCritialRate(caster: BattleRole, target: BattleRole): number {
        let critial = caster.attrMgr.getAttr(AttrType.cricialRate);

        let deCritial = target.attrMgr.getAttr(AttrType.deCricialRate);

        return Math.max(critial - deCritial, 0);
    }

    /**暴击伤害 */
    static getCriticalDamage(damage: number, caster: BattleRole, target: BattleRole): number {
        return damage * 1.5 >> 0;
    }

    /**增伤 */
    static getDamageAdd(damage: number, caster: BattleRole): number {
        return damage * (1 + Math.random()) >> 0;
    }

    /**减伤 */
    static getDamageReduce(damage: number, caster: BattleRole): number {
        return damage * (1 - Math.random()) >> 0
    }

    /**吸血 */
    static getXixue(damage: number, caster: BattleRole): number {
        return 0;
    }

    /**反伤 */
    static getFanshang(damage: number, caster: BattleRole): number {
        return 0;
    }
}
